package com.eduorder.controller;


import com.R;
import com.eduorder.service.PayLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 支付日志表 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-07-20
 */
@RestController
@RequestMapping("/eduorder/pay-log")
@CrossOrigin
public class PayLogController {

	@Autowired
	private PayLogService payLogService;

	@GetMapping("/createNative/{orderNo}")
	public R createNative(@PathVariable("orderNo") String orderNo){

		Map map = payLogService.createNative(orderNo);
		System.out.println("---------------返回创建二维码map集合"+map);
		return R.ok().data(map);
	}

	@GetMapping("/queryStatus/{orderNo}")
	public R queryStatus(@PathVariable("orderNo") String orderNo){
		System.out.println(orderNo);
		Map<String,String> map = payLogService.queryPayStatus(orderNo);
		System.out.println("---------------返回查询二维码map集合"+map);

		if (map == null){
			return R.error().message("支付出错了");
		}
		//如果返回map不为空，通过map获取订单状态
		if (map.get("trade_state").equals("SUCCESS")){
			payLogService.updateOrderStatus(map);
			return R.ok().message("支付成功");
		}
		return R.ok().code(25000).message("支付中");
	}
}

